package com.base.controller;

import com.base.entity.bo.ExpertBo;
import com.base.entity.bo.ExpertGroupBO;
import com.base.entity.bo.OrganizationBo;
import com.base.entity.bo.SciencePersonBo;
import com.base.entity.vo.ExpertVo;
import com.base.entity.vo.OrganizationVo;
import com.base.entity.vo.SciencePersonVo;
import com.base.service.OrganizationService;
import com.base.service.SciencePersonService;
import com.base.utils.CutPageBean;
import com.base.utils.Result;
import com.common.utils.poi.ExcelUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Api(tags = "组织机构")
@RestController
@RequestMapping("/zjfz")
public class OrganizationController {
    @Autowired
    OrganizationService organizationService;

    @PostMapping("/selectOrganizationList")
    @ApiOperation(value = "查询组织结构列表")
    public Result selectOrganizationList(@RequestBody OrganizationVo organizationVo){
        CutPageBean<OrganizationBo> cutPageBean =organizationService.selectOrganizationList(organizationVo);
        return Result.succ(cutPageBean);
    }

    @PostMapping("/insertOrganizationList")
    @ApiOperation(value = "新增单位")
    public Result insertOrganizationList(@RequestBody OrganizationBo organizationBo){
        int row=organizationService.insertOrganizationList(organizationBo);
        if (row > 0) {
            return Result.succ("新增成功");
        } else {
            return Result.fail("新增失败");
        }
    }

    @PostMapping("/deleOrganizationList")
    @ApiOperation(value = "删除单位")
    public Result deleOrganizationList(@RequestBody OrganizationBo organizationBo){
        int row=organizationService.deletOrganizationList(organizationBo);
        if (row > 0) {
            return Result.succ("删除成功");
        } else {
            return Result.fail("删除失败");
        }
    }


    @PostMapping("/deletLexelOrganizationList")
    @ApiOperation(value = "删除二级单位")
    public Result deletLexelOrganizationList(@RequestBody OrganizationBo organizationBo){
        int row=organizationService.deletLexelOrganizationList(organizationBo);
        if (row > 0) {
            return Result.succ("删除成功");
        } else {
            return Result.fail("删除失败");
        }
    }

    @PostMapping("/updateOrganizationList")
    @ApiOperation(value = "编辑单位")
    public Result updateOrganizationList(@RequestBody OrganizationBo organizationBo){
        int row=organizationService.updateOrganizationList(organizationBo);
        if (row > 0) {
            return Result.succ("更新成功");
        } else {
            return Result.fail("更新失败");
        }
    }

    @PostMapping("/organizationListDetails")
    @ApiOperation(value = "查询单位详情")
    public Result organizationListDetails(@RequestBody OrganizationVo organizationVo){
        List<OrganizationBo> list =organizationService.organizationListDetails(organizationVo);
        return Result.succ(list);
    }

    @PostMapping("/insertLevelOrganizationList")
    @ApiOperation(value = "新增二级单位")
    public Result insertLevelOrganizationList(@RequestBody OrganizationBo organizationBo){
        int row=organizationService.insertLevelOrganizationList(organizationBo);
        if (row > 0) {
            return Result.succ("新增成功");
        } else {
            return Result.fail("新增失败");
        }
    }


    @PostMapping("/levelOrganizationList")
    @ApiOperation(value = "查询二级单位")
    public Result levelOrganizationList(@RequestBody OrganizationVo organizationVo){
        List<OrganizationBo> list =organizationService.levelOrganizationList(organizationVo);
        return Result.succ(list);
    }

    @ApiOperation("导出职称类别列表")
    @PostMapping("/exportList")
    public void exportList(HttpServletResponse response, @RequestBody OrganizationVo organizationVo) {
        List<OrganizationBo> list =organizationService.exportList(organizationVo);
        ExcelUtil<OrganizationBo> util = new ExcelUtil<>(OrganizationBo.class);
        util.exportExcel(response, list, "组织机构列表","组织机构列表");
    }
}
